﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;
using System.Data;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_FIM_MAS_BankAccounts : IBLL_FIM_MAS_BankAccounts
    {
        Common common = new Common();
        private static readonly IDAL_FIM_MAS_BankAccounts dal = DataAccess.Create_FIM_MAS_BankAccounts();

        public B_FIM_MAS_BankAccounts()
        {

        }

        public IList<M_FIM_MAS_BankAccounts> GetFull()
        {
            return GetFull(null);
        }

        public IList<M_FIM_MAS_BankAccounts> GetFull(string bank_acc_type_grp_seq)
        {
            Nullable<int> nbank_acc_type_grp_seq = common.ConvertNullInt(bank_acc_type_grp_seq);

            return dal.GetFull(nbank_acc_type_grp_seq);
        }

        public IList<M_FIM_MAS_BankAccounts> GetFull(string bank_acc_type_grp_seq
            , string bgm_source_seq)//, string sub_source_seq)
        {
            Nullable<int> nbank_acc_type_grp_seq = common.ConvertNullInt(bank_acc_type_grp_seq);
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            //Nullable<int> nsub_source_seq = common.ConvertNullInt(sub_source_seq);

            return dal.GetFull(nbank_acc_type_grp_seq, nbgm_source_seq);//, nsub_source_seq);
        }

        public IList<M_FIM_MAS_BankAccounts> GetList(string bank_acc_type_grp_seq, string bgm_source_seq, string bank_seq, string branch_seq, bool bAdvance = false)
        {
            Nullable<int> nbank_acc_type_grp_seq = common.ConvertNullInt(bank_acc_type_grp_seq);
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbank_seq = common.ConvertNullInt(bank_seq);
            Nullable<int> nbranch_seq = common.ConvertNullInt(branch_seq);

            return dal.GetList(nbank_acc_type_grp_seq, nbgm_source_seq, nbank_seq, nbranch_seq, bAdvance);
        }

        public M_FIM_MAS_BankAccounts GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public DataTable GetBankAccountHistory(string bank_acc_seq, DateTime? dFromDate, DateTime? dToDate)
        {
            int nSeq;

            if (bank_acc_seq == null)
                return null;

            if (common.IsNumeric(bank_acc_seq))
            {
                nSeq = int.Parse(bank_acc_seq);
                return dal.GetBankAccountHistory(nSeq, dFromDate, dToDate);
            }
            else
            {
                return null;
            }
        }

        public DataTable GetBankAccountReport(int bank_acc_seq, DateTime? dFromDate, DateTime? dToDate)
        {
            return dal.GetBankAccountReport(bank_acc_seq, dFromDate, dToDate);
        }

        public DataTable SumAmountReport(int bank_acc_seq, DateTime? dFromDate, DateTime? dToDate)
        {
            return dal.SumAmountReport(bank_acc_seq, dFromDate, dToDate);
        }

        public void Insert(M_FIM_MAS_BankAccounts info)
        {
            try
            {
                dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_FIM_MAS_BankAccounts info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_FIM_MAS_BankAccounts info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }
    }
}
